package org.john.guavatest;

import com.google.common.cache.*;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.BaseEncoding;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by adsame on 17-1-23.
 */
public class GuavaTest {
    private static GuavaTest gt = new GuavaTest();

    public static GuavaTest getInstance() {
        return gt;
    }

    private GuavaTest() {

    }


    public static void main(String[] args) {
        Set<String> styleSet =
                ImmutableSet.of("0", "5", "7");
        Set<String> set = new HashSet();
        set.add("7");
        if (Collections.disjoint(styleSet, set)) {
            System.out.println("disj is true");
        } else {
            System.out.println("disj is false");
        }
        BaseEncoding b64 = BaseEncoding.base64Url().omitPadding();
        String str = new String(b64.decode(b64.encode("test".getBytes())));
        System.out.println("result:" + str);
        Cache<IDAndParty, Integer> cache = CacheBuilder.newBuilder().concurrencyLevel(2).maximumWeight(100).
                weigher(new Weigher<IDAndParty, Integer>() {
                    public int weigh(IDAndParty key, Integer value) {
                        return value;
                    }
                }).build();
        IDAndParty id = new IDAndParty("3", "baidu");
        cache.put(id, 50);
//        for (int i = 0; i < 100; ++i) {
//            cache.getIfPresent(id);
//        }
        System.out.println(cache.getIfPresent(id));
        IDAndParty id2 = new IDAndParty("4", "baidu");
        cache.put(id2, 1);
        Integer i = cache.getIfPresent(id2);
        System.out.println(cache.getIfPresent(id));
        System.out.println(cache.asMap());
        cache.invalidate(id2);
        System.out.println(cache.getIfPresent(id2));
        System.out.println("value:" + i);
    }
}
